﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class sysManage_LoginLog : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //if (Session["UserName"] == null)
            //{
            //    Response.Write("<script language=javascript>alert('请先登录!');window.location.href='../Login.aspx'</script>");
            //}
            //else
            //{
                Bind();
            //}
        }
    }

    public void Bind()
    {
        DataSet ds = new DataSet();
        sysSelect ss = new sysSelect();
        string strsql = "select * from LoginInfo";
        ds = ss.SelectInfo(strsql);
        DataTable dt = new DataTable();
        dt = ds.Tables[0];
        DataColumn dc = dt.Columns.Add("number", System.Type.GetType("System.String"));
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            dt.Rows[i]["number"] = (i + 1).ToString();
        }

        DataView dv = ds.Tables[0].DefaultView;
        PagedDataSource pds = new PagedDataSource();
        AspNetPager1.RecordCount = dv.Count;
        pds.DataSource = dv;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
        pds.PageSize = AspNetPager1.PageSize;
        this.GridView1.DataSource = pds;
        this.GridView1.DataBind();
    }
    protected void chkAll_CheckedChanged(object sender, EventArgs e)
    {

        foreach (GridViewRow row in GridView1.Rows)
        {

            CheckBox ckTemp = (CheckBox)row.FindControl("chkDo");
            if (ckTemp != null)
            {
                if (chkAll.Checked)
                {
                    ckTemp.Checked = true;
                }
                else
                {
                    ckTemp.Checked = false;
                }
            }
            else
            {
                Response.Write("<script language=javascript>alert('没有值');</script>");
                
            }

        }
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        //if (Convert.ToInt32(Session["Purview"]) > 5)
        //{
        try
        {
            sysDelete sd = new sysDelete();
            bool blSelected = false;
            int j = this.GridView1.Rows.Count;
            for (int i = 0; i < j; i++)
            {
                CheckBox ckTemp = (CheckBox)GridView1.Rows[i].FindControl("chkDo");
                if (ckTemp.Checked)
                {
                    blSelected = true;
                    string strId = this.GridView1.DataKeys[i]["LoginID"].ToString();

                    string strDel = "delete from LoginInfo where LoginID=" + strId;
                    sd.LoginInfoDel(strDel);


                }
            }
            if (blSelected == false)
            {
                Response.Write("<script language=javascript>alert('请先选择一条要操作的信息!');</script>");
            }

            Bind();//重新绑定数据
        }
        catch 
        {
            Response.Write("<script language=javascript>alert('错误！');</script>");
        }
        //}
        //else
        //{
        //    Response.Write("<script language=javascript>alert('对不起,您没有此权限！！');</script>");
        //}
    }
}
